// CherryMerry ( Mikhail Tomilenko ), Reverse Entertainment, 2021-2024


#include "../Public/PlayerCurrencyManager.h"

UPlayerCurrencyManager::UPlayerCurrencyManager()
{
	PrimaryComponentTick.bCanEverTick = false;

	MaxCurrencyAmount = 300000;
}


void UPlayerCurrencyManager::BeginPlay()
{
	Super::BeginPlay();

	
}


void UPlayerCurrencyManager::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

}

void UPlayerCurrencyManager::AddCurrency(int32 AmountToAdd)
{
	if (CurrentCurrencyAmount != MaxCurrencyAmount)
	{
		int32 CurrencyAfterAdd = CurrentCurrencyAmount + AmountToAdd;
		if (CurrencyAfterAdd >= MaxCurrencyAmount)
		{
			CurrentCurrencyAmount = MaxCurrencyAmount;
		}
		else
		{
			CurrentCurrencyAmount += AmountToAdd;
		}
	}
}

void UPlayerCurrencyManager::UseCurrency(int32 AmountToUse)
{
	if (CurrentCurrencyAmount != 0)
	{
		int32 CurrencyAfterUse = CurrentCurrencyAmount - AmountToUse;
		if (CurrencyAfterUse < 0)
		{
			CurrentCurrencyAmount = 0;
		}
		else
		{
			CurrentCurrencyAmount -= AmountToUse;
		}
	}
}

